import java.util.Arrays;

public class Solution821 {
    public int[] shortestToChar(String s, char c) {
        int[] ans=new int[s.length()];
        Arrays.fill(ans,Integer.MAX_VALUE);
        char[] chars=s.toCharArray();
        int cur=-1;
        for (int i=0;i<chars.length;i++){
            if (chars[i]==c){
                cur=0;
            }else if (cur!=-1){
                cur++;
            }
            if (cur!=-1) {
                ans[i] = Math.min(ans[i], cur);
            }
        }
        cur=-1;
        for (int i=chars.length-1;i>=0;i--){
            if (chars[i]==c){
                cur=0;
            }else if (cur!=-1){
                cur++;
            }
            if (cur!=-1) {
                ans[i] = Math.min(ans[i], cur);
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Solution821().shortestToChar("loveleetcode", 'e')));
    }
}
